package com.xdu.math.Controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import com.xdu.math.Service.DeterminantService;
import com.xdu.math.Entity.CommonResponse;
import com.xdu.math.Entity.SquareMatrix;
import com.xdu.math.Config.Constant;

@Controller
@RequestMapping("/rest")
@Slf4j
@CrossOrigin(origins = "*")
public class DeterminantController {
    @Autowired
    private DeterminantService determinantService;

    @ResponseBody
    @RequestMapping(value="/calculateDeterminant2x2",method= RequestMethod.POST)
    public CommonResponse<Float> calculateDeterminant2x2(@RequestBody SquareMatrix d2){
        CommonResponse<Float> commonResponse = new CommonResponse<>();
        try{
            commonResponse.setData(determinantService.calculateDeterminant2x2(d2));
            commonResponse.setCode(Constant.successCode);
        }catch(Exception e){
            log.error(e.getMessage());
            commonResponse.setCode(Constant.errorCode);
        }
        return commonResponse;
    }
}
